package zy.blue7.im.core.channelhandler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import zy.blue7.im.common.message.Message;
import zy.blue7.im.core.other.Container;
import zy.blue7.im.core.service.MessageHandler;

/**
 * @author blue7
 * @version 1.0
 * @date 2022/3/1 16:16
 */
public class LastHandler extends SimpleChannelInboundHandler<Message> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Message message) throws Exception {
        /**
         * 从map中获取 指定的处理器进行处理
         */
        MessageHandler messageHandler = (MessageHandler) Container.handlerMap.get(message.getClass());

        messageHandler.handle(message, ctx.channel());

    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        ctx.channel().close();
    }
}
